package org.abc.fund.repository.factorRepository;

import org.abc.fund.entity.factorEntity.Factor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 因子Repository
 */
@Repository
public interface FactorRepository extends JpaRepository<Factor, Long> {
    
    /**
     * 根据因子代码查找因子
     */
    Optional<Factor> findByFactorCode(String factorCode);
    
    /**
     * 根据因子类型查找因子列表
     */
    List<Factor> findByFactorType(String factorType);


    /**
     * 根据是否启用查找因子列表
     */
    List<Factor> findByEnabled(Boolean enabled);
    
    /**
     * 统计启用的因子数量
     */
    long countByEnabledTrue();
    
    /**
     * 根据因子名称模糊查询
     */
    List<Factor> findByFactorNameContaining(String factorName);
    
    /**
     * 根据因子代码模糊查询
     */
    List<Factor> findByFactorCodeContaining(String factorCode);
    
    /**
     * 分页查询因子
     */
    Page<Factor> findByFactorTypeAndEnabled(String factorType, Boolean enabled, Pageable pageable);
    

    /**
     * 检查因子代码是否存在
     */
    boolean existsByFactorCode(String factorCode);
    

    /**
     * 统计指定因子类型的因子数量
     */
    long countByFactorType(String factorType);
    
    /**
     * 统计指定启用状态的因子数量
     */
    long countByEnabled(boolean enabled);

    Page<Factor> findByFactorNameContainingAndFactorTypeAndEnabled(String factorName, String factorType, Boolean enabled, Pageable pageable);
    Page<Factor> findByFactorCodeContainingAndFactorTypeAndEnabled(String factorCode, String factorType, Boolean enabled, Pageable pageable);
    Page<Factor> findByFactorNameContainingAndFactorType(String factorName, String factorType, Pageable pageable);
    Page<Factor> findByFactorCodeContainingAndFactorType(String factorCode, String factorType, Pageable pageable);
    Page<Factor> findByFactorNameContainingAndEnabled(String factorName, Boolean enabled, Pageable pageable);
    Page<Factor> findByFactorCodeContainingAndEnabled(String factorCode, Boolean enabled, Pageable pageable);
    Page<Factor> findByFactorNameContaining(String factorName, Pageable pageable);
    Page<Factor> findByFactorCodeContaining(String factorCode, Pageable pageable);

    Page<Factor> findByFactorType(String factorType, Pageable pageable);
    Page<Factor> findByEnabled(Boolean enabled, Pageable pageable);
} 